package com.bear.sgg.springboot_09_mybatis.mapper;


import com.bear.sgg.springboot_09_mybatis.entity.Department;
import org.apache.ibatis.annotations.*;

/**
 * @ClassNmae DepartmentMapper
 * @Description TODO
 * @Author bear
 * @Date 2020/3/15 0015 上午 11:12
 */
//不想写@Mapper注解的话，可以在xxxApplication类中配置@MapperScan("com.bear.sgg.springboot_09_mybatis.mapper")注解以便扫描mapper包
@Mapper
public interface DepartmentMapper {

    @Select("select * from department where id=#{id}")
    public Department selectById(Integer id);

    @Delete("delete from department where id=#{id}")
    public int deleteById(Integer id);

    //通过@Options注解中的useGeneratedKeys和keyProperty属性可以将主键值插入到传入对象中，即插入数据后传入对象的主键属性会被赋值
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into department (department_name) values(#{departmentName})")
    public int insertDept(Department department);

    @Update("update department set department_name=#{departmentName} where id=#{id}")
    public int updateDept(Department department);
}
